﻿(function () {
    var api = {};

    function CustomNumberOverlay(point, num) {
        this._point = point;
        this._num = parseInt(num, 10);
        this._div = document.createElement("div");
    }
    CustomNumberOverlay.prototype = new BMap.Overlay();
    CustomNumberOverlay.prototype.initialize = function (map) {
        this._map = map;
        var div = this._div;
        div.className = 'customNumberMarker';
        div.innerText = this._num;
        div.textContent = this._num;
        div.style.borderRadius = this._num.toString().length * 6 + 'px';
        div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
        map.getPanes().markerPane.appendChild(div);
        return div;
    };
    CustomNumberOverlay.prototype.draw = function () {
        var map = this._map;
        var pixel = map.pointToOverlayPixel(this._point);
        //console.log(pixel.x - this._div.style.width / 2 + "px");
        this._div.style.left = pixel.x - 18 / 2 + "px";
        this._div.style.top = pixel.y - 25 + "px";
    };
    CustomNumberOverlay.prototype.addEventListener = function (event, fun) {
        if (event == 'click' && 'ontouchstart' in this._div) {
            return this._div['ontouchstart'] = fun;
        }
        this._div['on' + event] = fun;
    };

    function BackCenterControl(anchor, offset) {
        this.defaultAnchor = anchor || BMAP_ANCHOR_BOTTOM_LEFT;
        this.defaultOffset = offset || new BMap.Size(10, 35);
        this._div = document.createElement("div");
    }
    BackCenterControl.prototype = new BMap.Control();
    BackCenterControl.prototype.initialize = function (map) {
        var div = this._div;
        div.className = 'backCenterControl';
        map.getContainer().appendChild(div);
        return div;
    };
    BackCenterControl.prototype.addEventListener = function (event, fun) {
        if (event == 'click' && 'ontouchstart' in this._div) {
            return this._div['ontouchstart'] = fun;
        }
        this._div['on' + event] = fun;
    };

    api.CustomNumberOverlay = CustomNumberOverlay;
    api.BackCenterControl = BackCenterControl;
    window.MapExt = api;
})();